﻿using LL2025.Libs.Queue;

namespace MAUILL.Pages
{
    public partial class MainPage : ContentPage
    {
        public MainPage(MainPageModel model)
        {
            InitializeComponent();
            BindingContext = model;
            Loaded += MainPage_Loaded;
        }

        private async void MainPage_Loaded(object? sender, EventArgs e)
        {
            var config = new BusConfig
            {
                RabbitMqHost = "124.221.160.244",
                QueueName = "queue_remmi", //只要订阅者队列名不同，同样类型的，就可以推给每个人，一样轮询推送
                Username = "ll",
                Password = "123456",
            };

            using var busManager = new BusManager(config);

            // 订阅消息接收事件
            busManager.MessageReceived += async (message) =>
            {
                // 使用 MainThread.InvokeOnMainThreadAsync 确保在主线程中执行 UI 更新
                await MainThread.InvokeOnMainThreadAsync(async () =>
                {
                    await DisplayAlert("标题", $"{message.CustomerNumber}这是一个简单的弹框！", "确定");
                });
            };

            await busManager.StartAsync();
        }
    }
}